import axios from "axios";
import store  from "@/store";

// 进度条
import nprogress from "nprogress";
import "nprogress/nprogress.css";

const requests = axios.create({
  // 配置默认对象
  /* 设置默认路径 */
  // baseURL: "http://8.134.214.53:3000/",
  baseURL: "http://localhost:3000/",
  // 请求回来时间超过5秒就失败
  timeout: 10000,
  withCredentials: true,
});

// console.log(this)
// 设置发送请求前
requests.interceptors.request.use((config) => {

  nprogress.start();
  
  return config;
});
// 设置响应信息
requests.interceptors.response.use(
  (res) => {
    // 请求成功消失
    nprogress.done();

    return res.data;
  },
  (error) => {
    // 失败弹出错误
    return Promise.reject(new Error("faile"));
  }
);

export default requests;
